package com.niit.service.impl;

import com.niit.dao.StudentDao;
import com.niit.entity.Student;
import com.niit.service.StudentService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.awt.print.Pageable;
import java.util.List;

@Service("studentService")
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentDao studentDao;

    @Override
    public Student queryById(String sid) {
        return this.studentDao.queryById(sid);
    }

    @Override
    public Page<Student> queryByPage(Student student, PageRequest pageRequest) {
        long total = this.studentDao.count(student);
        return new PageImpl<>(this.studentDao.queryAllByLimit(student,pageRequest),pageRequest,total);

    }

    @Override
    public Student insert(Student student) {
        this.studentDao.insert(student);
        return student;    }

    @Override
    public Student update(Student student) {
        this.studentDao.update(student);
        return this.queryById(student.getSid());
    }

    @Override
    public boolean deleteById(String sid) {
        return this.studentDao.deleteById(sid) > 0;    }

    @Override
    public List<Student> queryByConditions(Student student) {
        return this.studentDao.queryByConditions(student);    }
}
